package com.qf.ssm.controller;

import com.qf.ssm.common.request.ActivityRequestParams;
import com.qf.ssm.common.request.CustomerRequestParams;
import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Activity;
import com.qf.ssm.entity.Customer;
import com.qf.ssm.service.MarketingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86155
 * @ClassName: com.qf.ssm.controller.MarketingController
 * @Description: 营销活动类，三种活动
 * @date: 2021/10/13 9:19
 */
@RestController
@RequestMapping("/market")
public class MarketingController {
    @Resource
    private MarketingService marketingService;

    /**
     * 展示满减活动列表,有参数则检索查询展示
     *
     * @param startDate
     * @param endDate
     * @param status
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/activity/list")
    public ResponseResult<List<Activity>> listActivity(String startDate, String endDate, Integer status,
                                                       @RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer size) {
        List<Activity> activities = marketingService.listActivity(startDate, endDate, status, page, size);
        return ResponseResult.success(activities);
    }

    /**
     *
     * @param activityRequestParams
     *   "activityId": 0,
     *   "startDate": "2021-10-14 15:03:06",
     *   "endDate": "2021-10-14 15:03:06",
     *   "activityCycle": "demoData",
     *   "startTime": " 15:03:06", 类型必须不带日期
     *   "endTime": " 15:03:06",
     *   "content": "demoData"
     * @return
     */
    @PostMapping("/activity/add")
    public ResponseResult<Boolean> addActivity(@RequestBody ActivityRequestParams activityRequestParams) {
        Boolean isAdd = marketingService.addActivity(activityRequestParams);
        return ResponseResult.success(isAdd);
    }

    @PutMapping("/activity/update")
    public ResponseResult<Boolean> updateActivity(@RequestBody ActivityRequestParams activityRequestParams) {
        Boolean isUpdate = marketingService.updateActivity(activityRequestParams);
        return ResponseResult.success(isUpdate);
    }

    @DeleteMapping("/activity/delete/{aid}")
    public ResponseResult<Boolean> deleteActivity(@PathVariable("aid") Long aid) {
        Boolean isDelete = marketingService.deleteActivity(aid);
        return ResponseResult.success(isDelete);
    }

    /**
     * 展示新客满减活动列表,有参数则检索查询展示
     *
     * @param startDate
     * @param endDate
     * @param status
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/customer/list")
    public ResponseResult<List<Customer>> listCustomer(String startDate, String endDate, Integer status,
                                                       @RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer size) {
        List<Customer> customers = marketingService.listCustomer(startDate, endDate, status, page, size);
        return ResponseResult.success(customers);
    }

    @PostMapping("/customer/add")
    public ResponseResult<Boolean> addCustomer(@RequestBody CustomerRequestParams customerRequestParams) {
        Boolean isAdd = marketingService.addCustomer(customerRequestParams);
        return ResponseResult.success(isAdd);
    }

    @PutMapping("/customer/update")
    public ResponseResult<Boolean> updateCustomer(@RequestBody CustomerRequestParams customerRequestParams) {
        Boolean isUpdate = marketingService.updateCustomer(customerRequestParams);
        return ResponseResult.success(isUpdate);
    }

    @DeleteMapping("/customer/delete/{cid}")
    public ResponseResult<Boolean> deleteCustomer(@PathVariable("cid") Long cid) {
        Boolean isDelete = marketingService.deleteCustomer(cid);
        return ResponseResult.success(isDelete);
    }
}
